package com.lxp.project.system.service.impl;

import com.lxp.common.utils.SecurityUtils;
import com.lxp.framework.web.domain.AjaxResult;
import com.lxp.project.system.domain.SysUser;
import com.lxp.project.system.mapper.SysUserMapper;
import com.lxp.project.system.service.ISysRegisterService;
import com.lxp.project.system.service.ISysUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 用户 业务层处理
 *
 * @author Administrator
 */
@Service
public class SysRegisterServiceImpl implements ISysRegisterService {

    @Resource
    private SysUserMapper userMapper;

    @Resource
    private ISysUserService sysUserService;

    @Override
    public AjaxResult register(SysUser sysUser) {
        Long[] roleIds = new Long[]{3L};
        sysUser.setSex("1");
        sysUser.setRoleIds(roleIds);
        sysUser.setStatus("0");
        sysUser.setDelFlag("0");
        sysUser.setCompanyId(1L);
        sysUser.setUserType(2);//2用户1医生0管理员
        sysUser.setPassword(SecurityUtils.encryptPassword(sysUser.getPassword()));
        int i = userMapper.insertUser(sysUser);
        sysUserService.insertUserRole(sysUser);
        if (i > 0) {
            return AjaxResult.success();
        } else {
            return AjaxResult.error();
        }
    }
}
